package com.foreveross.weixin.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.foreveross.weixin.common.Constant;
import com.foreveross.weixin.util.StringUtil;
import com.foreveross.weixin.util.WeixinUtil;
import com.foreveross.weixin.vo.AccessToken;
import com.foreveross.weixin.vo.pojo.Button;
import com.foreveross.weixin.vo.pojo.CommonButton;
import com.foreveross.weixin.vo.pojo.ComplexButton;
import com.foreveross.weixin.vo.pojo.Menu;
import com.foreveross.weixin.vo.pojo.ViewButton;


  
/** 
 * 菜单管理器类 
 *  
 * @author wm 
 * @date 2014-03-19
 */  
public class MenuManager {  
    private static Logger log = LoggerFactory.getLogger(MenuManager.class);  
  
    public static void main(String[] args) {  
       
  
        // 调用接口获取access_token  
        AccessToken at = WeixinUtil.getAccessToken(Constant.appId, Constant.appSecret);  
        if (null != at) {  
            // 调用接口创建菜单  
            int result = WeixinUtil.createMenu(getMenu(), at.getAccess_token());  
  
            // 判断菜单创建结果  
            if (0 == result)  
                log.info("菜单创建成功！");  
            else  
                log.info("菜单创建失败，错误码：" + result);  
        }  
    }  
  
    /** 
     * 组装菜单数据 
     *  
     * @return 
     */  
    private static Menu getMenu() {  
    	
    	ViewButton viewButton1 = new ViewButton();
    	viewButton1.setName("物业服务");
    	viewButton1.setType(Constant.VIEW_BUTTON_EVENT);
    	viewButton1.setUrl("http://crcszwy.com/WeChatForeEnd/index/propertyCenterAuthorize.html");
  
    	ViewButton viewButton21 = new ViewButton();
    	viewButton21.setName("新闻资讯");
    	viewButton21.setType(Constant.VIEW_BUTTON_EVENT);
    	viewButton21.setUrl("http://crcszwy.com/WeChatForeEnd/index/newsCenterAuthorize.html?newsType=0");
    	
    	ViewButton viewButton22 = new ViewButton();
    	viewButton22.setName("新盘展示");
    	viewButton22.setType(Constant.VIEW_BUTTON_EVENT);
    	viewButton22.setUrl("http://crcszwy.com/WeChatForeEnd/index/newsCenterAuthorize.html?newsType=1");
    	
    	ViewButton viewButton23 = new ViewButton();
    	viewButton23.setName("万象专区");
    	viewButton23.setType(Constant.VIEW_BUTTON_EVENT);
    	viewButton23.setUrl("http://crcszwy.com/WeChatForeEnd/index/newsCenterAuthorize.html?newsType=2");
    	
        ComplexButton mainBtn2 = new ComplexButton();  
        mainBtn2.setName("资讯中心");  
        mainBtn2.setSub_button(new Button[] { viewButton21, viewButton22, viewButton23 });  
        
    	
        ViewButton viewButton31 = new ViewButton();
    	viewButton31.setName("访客登记");
    	viewButton31.setType(Constant.VIEW_BUTTON_EVENT);
    	viewButton31.setUrl("http://crcszwy.com/WeChatForeEnd/index/visitorRegisterAuthorize.html");
    	
    	ViewButton viewButton32 = new ViewButton();
     	viewButton32.setName("住户认证");
     	viewButton32.setType(Constant.VIEW_BUTTON_EVENT);
     	viewButton32.setUrl("http://crcszwy.com/WeChatForeEnd/index/userCertificateAuthorize.html");
    	
    	
    	ComplexButton mainBtn3 = new ComplexButton();  
        mainBtn3.setName("住户中心");  
        mainBtn3.setSub_button(new Button[] { viewButton31, viewButton32});  
 
        Menu menu = new Menu();  
        menu.setButton(new Button[] { viewButton1, mainBtn2, mainBtn3 });  
  
        return menu;  
    }
}  
